package ${package}.backstage.service.imple;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.TypeReference;
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import ${package}.backstage.service.${ClassName}Service;
import ${package}.common.model.User;
import ${package}.dao.entity.${moduleName}.${ClassName};
import ${package}.dao.mapper.${moduleName}.${ClassName}Mapper;
import ${package}.dao.vo.${moduleName}.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import ${package}.common.model.PageResponse;

import java.util.List;

/**
* ${tableComment}
*
* @author ${author} ${email}
* @since ${version} ${date}
*/
@Service
public class ${ClassName}ServiceImpl implements ${ClassName}Service {
    @Autowired
    private ${ClassName}Mapper ${className}Mapper;
    /**
     * 查询${tableComment}
     *
     * @param id ${tableComment}主键
     * @return ${tableComment}
     */
    @Override
    public ${ClassName} select${ClassName}ById(Long id){
        ${ClassName} ${className} = ${className}Mapper.select${ClassName}ById(id);
        return ${className};
    }

    /**
     * 查询${tableComment}列表
     *
     * @param searchVO ${tableComment}
     * @return ${tableComment}
     */
    @Override
    public PageResponse<${ClassName}Result> select${ClassName}List(${ClassName}SearchParam searchVO){
        ${ClassName} ${className} = Convert.convert(${ClassName}.class,searchVO);
        PageHelper.startPage(searchVO.getPage(), searchVO.getPageSize());
        List<${ClassName}> pageResult = ${className}Mapper.select${ClassName}List(${className});
        PageInfo pageInfo = new PageInfo(pageResult);
        long total = pageInfo.getTotal();
        List<${ClassName}Result> list=Convert.convert(new TypeReference<List<${ClassName}Result>>() {},pageInfo.getList());
        PageResponse<${ClassName}Result> pageResponse = PageResponse.build(total, list);
        return pageResponse;
    }

    /**
     * 新增${tableComment}
     *
     * @param createParam ${tableComment}
     * @param user
     * @return 结果
     */
    @Override
    public int insert${ClassName}(${ClassName}CreateParam createParam, User user){
        ${ClassName} ${className} = Convert.convert(${ClassName}.class, createParam);
        return ${className}Mapper.insertSelective(${className});
    }

    /**
     * 修改${tableComment}
     *
     * @param updateParam ${tableComment}
     * @param user
     * @return 结果
     */
    @Override
    public int update${ClassName}(${ClassName}UpdateParam updateParam, User user){
        ${ClassName} ${className} = Convert.convert(${ClassName}.class, updateParam);
        return ${className}Mapper.updateByPrimaryKeySelective(${className});
    }

    /**
     * 批量删除${tableComment}
     *
     * @param ids 需要删除的${tableComment}主键
     * @return 结果
     */
    @Override
    public int delete${ClassName}ByIds(String ids){
        if (StrUtil.isBlank(ids)) {
            throw new RuntimeException("参数不能为空！");
        }
        return ${className}Mapper.delete${ClassName}ByIds(ids.split(","));
    }
}
